<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@include file="view/link.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>模板页面</title>

    <style type="text/css">
        .tab_user {
            border: 1px solid blue;
            width: 350px;
            border-collapse: collapse;
            margin: 10px auto;
        }

        td, th {
            border: 1px solid blue;
            padding: 7px;
        }

        #img_uphoto {
            width: 200px;
            height: 180px;
        }
    </style>
</head>
<body>
<c:choose>
    <%--如果没有登录则显示注册信息--%>
    <c:when test="${empty sessionScope.loginUser}">
        <form method="post" action="<c:url value='/user/login'/>">
            <table class="tab_user">
                <tr>
                    <th>用户名称:</th>
                    <td><input type="text" name="uname" value="张三"/></td>
                </tr>
                <tr>
                    <th>用户密码:</th>
                    <td><input type="password" name="upwd" value="123456"/></td>
                </tr>
                <tr>
                    <th><img src="<c:url value='/user/yzm'/>" id="img_yzm"/></th>
                    <td><input type="text" name="uyzm" value="1234"/></td>
                </tr>
                <tr>
                    <th colspan="2">
                        <input type="button" value="注册" id="but_regist"/>
                        &nbsp; &nbsp; &nbsp; &nbsp;
                        <input type="submit" value="登录"/>
                    </th>
                </tr>
            </table>
        </form>
    </c:when>
    <%--如果登录了显示用户头像，等级--%>
    <c:otherwise>
        <table class="tab_user">
            <tr>
                <th rowspan="3">
                    <img src="<c:url value='/img/${sessionScope.loginUser.uphoto}'/>" id="img_uphoto"/>
                </th>
                <td>${sessionScope.loginUser.uname}</td>
            </tr>
            <tr>
                <td>等级：${sessionScope.loginUser.lv}</td>
            </tr>
            <tr>
                <td>粉丝：${sessionScope.loginUser.fen.size()}</td>
            </tr>
        </table>
    </c:otherwise>
</c:choose>
<c:if test="${not empty requestScope.message}">
    <h3> ${requestScope.message}</h3>
</c:if>
<script type="text/javascript">
    //给图片添加点击时间展示 该人物信息
    $("#img_uphoto").mouseenter(function () {
        //为实现
        location.href = "${pageContext.request.contextPath}/user/show?uid=${sessionScope.loginUser.uid}";
    })
    //给img添加点击事件
    $(function () {
        $("#img_yzm").bind("click", function () {
            $("#img_yzm").attr("src", "<c:url value='/user/yzm?t='/>" + Math.random());
        });
    });

    //给but_regist添加点击事件
    $(function () {
        $("#but_regist").click(function () {
            location.href = "<c:url value='/index.jsp?pageName=user_regist.jsp'/>";
        });
    });

</script>
</body>
</html>